libxc: refactor memory allocation functions
authorWei Liu <wei.liu2@citrix.com>
Tue, 1 Dec 2015 11:39:16 +0000 (11:39 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 1 Dec 2015 12:13:33 +0000 (12:13 +0000)
commitc8eb0ec277ae387e78d685523e0fee633e46f046
tree1a651065d3cc74ee0f34ca16395604fdba783111
parent43e99d38cd9253267982f5c29205f2d273f7d65e
libxc: refactor memory allocation functions

There were some problems with the original memory allocation functions:
1. xc_dom_alloc_segment and xc_dom_alloc_pad ended up calling
   xc_dom_chk_alloc_pages while xc_dom_alloc_page open-coded everything.
2. xc_dom_alloc_pad didn't call dom->allocate.

Refactor the code so that:
1. xc_dom_alloc_{segment,pad,page} end up calling
   xc_dom_chk_alloc_pages.
2. xc_dom_chk_alloc_pages calls dom->allocate.

This way we avoid scattering dom->allocate over multiple locations and
open-coding.

Also change the return type of xc_dom_alloc_page to xen_pfn_t and return
an invalid pfn when xc_dom_chk_alloc_pages fails.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Tested-by: Ian Campbell <ian.campbell@citrix.com>
tools/libxc/include/xc_dom.h
tools/libxc/xc_dom_core.c